package cn.wyj.org.controller;

import cn.wyj.basic.util.AjaxResult;
import cn.wyj.basic.util.PageList;
import cn.wyj.org.domain.Systemdictionarydetail;
import cn.wyj.org.query.SystemdictionarydetailQuery;
import cn.wyj.org.service.SystemdictionarydetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stail")
public class SystemdictionarydetailController {

    @Autowired
    private SystemdictionarydetailService systemdictionarydetailService;

    // 查询所有
    @GetMapping
    public List<Systemdictionarydetail> findAll(){
        return systemdictionarydetailService.findAll();
    }
    // 分页查询
    @PostMapping
    public PageList<Systemdictionarydetail> queryByPage(@RequestBody SystemdictionarydetailQuery systemdictionarydetailQuery){
        return systemdictionarydetailService.queryByPage(systemdictionarydetailQuery);
    }

    // 添加
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        if (null == systemdictionarydetail.getId()){
            // 没有ID就执行添加
            systemdictionarydetailService.add(systemdictionarydetail);
        }else {
            // 修改
            systemdictionarydetailService.update(systemdictionarydetail);
        }
        return AjaxResult.me().success();
    }
//
//    // 删除
//    @DeleteMapping("{/id}")
//    public AjaxResult delete(@PathVariable("id") Long id){
//        systemdictionarydetailService.delete(id);
//        return AjaxResult.me().success();
//    }
    // 删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        systemdictionarydetailService.delete(id);
        return AjaxResult.me().success();
    }


    // 批量删除
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        systemdictionarydetailService.batchDel(ids);
        return AjaxResult.me().success();
    }

//    /**
//     * 根据部门id查询一个部门所有的员工
//     */
//    @GetMapping("/dept/{id}")
//    public List<Employee> findEmpByDeptId(@ApiParam(value = "ID属性", required = true) @PathVariable("id") Long deptId){
//        return employeeService.findEmpByDeptId(deptId);
//    }
    // 查询字典的明细
    @GetMapping("/type/{id}")
    public List<Systemdictionarydetail> findTailByType(@PathVariable("id") Long id){
        return systemdictionarydetailService.findTailByType(id);
    }
}
